#!/usr/bin/env python
# -*- coding:utf-8 -*-
import ConfigParser
def FetchRecord():
    with open('record')as fr:
        for record in fr:
            print record.strip()

def FetchBalance():
    InfoFile=ConfigParser.ConfigParser()
    InfoFile.read('info.txt')
    return InfoFile.getfloat('login','balance')

def GetCash():
    Balance=FetchBalance()
    UserGetCashNum=float(raw_input("你现在的余额是%s,输入提现金额："%Balance))
    if UserGetCashNum*1.05>Balance:
        print "取不出那么多!"
        return
    Balance=float(Balance-UserGetCashNum*1.05)
    InfoFile=ConfigParser.ConfigParser()
    InfoFile.read('info.txt')
    InfoFile.set("login","balance",Balance)
    InfoFile.write(open("info.txt","w"))
    print "取现成功！账户余额%s元" % FetchBalance()

def repay():
    Balance=FetchBalance()
    UserRepayment=float(raw_input("要还款金额："))
    Balance=Balance+UserRepayment
    InfoFile=ConfigParser.ConfigParser()
    InfoFile.read('info.txt')
    InfoFile.set('login',"balance",Balance)
    InfoFile.write(open("info.txt","w"))
    print "还款成功！账户余额%s元" % FetchBalance()

def transacount():
    TransToUser=raw_input("收款人姓名：")
    TransToCard=raw_input("收款人账号：")
    TransAcount=float(raw_input("转账金额："))
    InfoFile=ConfigParser.ConfigParser()
    InfoFile.read('info.txt')
    CardNum1=InfoFile.get(TransToUser,'cardnum')
    Balance1=InfoFile.getfloat(TransToUser,'balance')
    if InfoFile.has_section(TransToUser):
        if TransToCard==CardNum1:
            Balance=FetchBalance()-TransAcount
            Balance1+=TransAcount
            InfoFile.set('login','balance',Balance)
            InfoFile.set(TransToUser,"balance",Balance1)
            InfoFile.write(open("info.txt","w"))
            print("转账成功，您的余额是%s元"%FetchBalance())
            ConsumeRecord="time,转账至%s,%s元\n"%(TransToUser,TransAcount)
            with open('record','a')as fa:
                fa.write(ConsumeRecord)
        else:
            print "姓名或卡号不正确！"
    else:
        print("没有这个用户")

def creditcardweb():
    while True:
        creditweblist=["查询余额","取现","还款","转账","交易记录","退出"]
        for num,web in enumerate(creditweblist,1):
            print num,web
        UserSelect=raw_input("输入选择：")
        if UserSelect=='1':
            print FetchBalance()
        elif UserSelect=='2':
            GetCash()
        elif UserSelect=='3':
            repay()
        elif UserSelect=='4':
            transacount()
        elif UserSelect=='5':
            FetchRecord()
        elif UserSelect=='6':
            break
        else:
            print("输入错误!")

creditcardweb()